<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom title="简历设置" :isAppBtn="false"></HeadCustom>
		<view class="wrap">
			<view class="card">
				<view class="fboxRow Ycenter">
					<view class="tit font30 flex1">简历启用</view>
					<view class="action fboxRow Ycenter">
						<u-switch space="2" v-model="fromData.enableStatus" :inactiveValue="0" :activeValue="1" activeColor="#CC9870"
							inactiveColor="#E8EDF1" size="20" :asyncChange="true" @change="switchChange($event, 'enableStatus')">
						</u-switch>
					</view>
				</view>
				<view class="tips mt24 font26 lh44 color-ACB4C7">关闭后，将不会出现在数字职场里，对所有招聘者不展示</view>
			</view>
			<template v-if="fromData.enableStatus == 1">
				<view class="font26 mt32 color-E8CDA7 lh38">在名片中是否显示简历：</view>
				<view class="card mt32">
					<view class="fboxRow Ycenter">
						<view class="tit font30 flex1">企业招聘者可见</view>
						<view class="action fboxRow Ycenter">
							<u-switch space="2" v-model="fromData.showCardCompany" :inactiveValue="0" :activeValue="1" activeColor="#CC9870" inactiveColor="#E8EDF1"
								size="20" :asyncChange="true" @change="switchChange($event, 'showCardCompany')">
							</u-switch>
						</view>
					</view>
					<view class="line"></view>
					<view class="fboxRow Ycenter">
						<view class="tit font30 flex1">所有人可见</view>
						<view class="action fboxRow Ycenter">
							<u-switch space="2" v-model="fromData.showCardAll" :inactiveValue="0" :activeValue="1" activeColor="#CC9870" inactiveColor="#E8EDF1"
								size="20" :asyncChange="true" @change="switchChange($event, 'showCardAll')">
							</u-switch>
						</view>
					</view>
				</view>
			</template>
		</view>
		<ModelPublic ref="modelRef" title="温馨提示" confirmText="知道了" :isShowClose="true" :isShowCancelText="false" footerPosition="center" content="您的简历不完整，请完善简历后再启用" @confirm="setTips(false)" />
	</view>
</template>

<script>
	import { resumeSetting, resumeInfo } from '@/api/recruit.js';
	import ModelPublic from '@/components/model-public/index.vue'
	export default {
		components: {ModelPublic},
		data() {
			return {
				theme: getApp().globalData.appTheme,
				globalColor: getApp().globalData.globalColor,
				fromData: {
					id:'',
					enableStatus: 0,
					showCardAll: 0,
					showCardCompany: 0
				},
				isVita: false,
				isTips: false
			}
		},
		onShow() {
			this.getInit()
		},
		methods: {
			getInit() {
				resumeInfo().then(res => {
					if (res.data) {
						this.fromData = res.data;
						getApp().globalData.vitaTemp = res.data;
						if(!res.data.resumeOpen){
							this.isVita = true
						}
					}else{
						this.isVita = true
					}
				});
			},
			// 提示完善信息
			setTips(state){
				this.$refs.modelRef.show = state
			},
			switchChange(e,name){
				if(this.isVita) {
					this.setTips(true)
					this.fromData[name] = 0
				}else{
					const req = {
						id: this.fromData.id,
						enableStatus: this.fromData.enableStatus,
						showCardAll: this.fromData.showCardAll,
						showCardCompany: this.fromData.showCardCompany
					}
					req[name] = req[name] == 1 ? 0 : 1
					resumeSetting(req).then(res=>{
						this.fromData[name] = this.fromData[name] == 1 ? 0 : 1
					}).catch(err=>{
						this.fromData[name] = 0
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-wrap {
		min-height: calc(100vh);
	}
	.wrap{padding: 32rpx 40rpx;}
	.card{padding: 32rpx;
		background-color: var(--viewBgColor);
		border-radius:12rpx}
	.line {
		margin: 32rpx 0;
		height: 1rpx;
		background: var(--backgroundDivisionColor);
	}
</style>